package com.lzy.demo;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.adapter.Call;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.convert.StringConvert;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.utils.HttpUtils;
import com.lzy.okgo.utils.OkLogger;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicReference;

import static junit.framework.TestCase.assertNotNull;

public class BaseDetailsAbilityTest {


    @Test
    public void onStart() throws Exception {

        assertNotNull("123456");

        final AtomicReference<Response<String>> responseRef = new AtomicReference<>();
        OkGo.<String>get("https://httpbin.org/get")
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        responseRef.set(response);

                    }
                });
//
////        Assert.fail();
////        Assert.assertNotNull("009090");
        assertNotNull(responseRef.get().body());

//        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
//        assertEquals("com.lzy.demo", actualBundleName);
//        assertNotNull("com.lzy.demo");

        // 同步会阻塞主线程，必须开新线程发起请求
        Call<String> call = OkGo.<String>get("https://httpbin.org/get")
                .tag(this)
                .headers("header1", "headerValue1")
                .params("param1", "syncGet")
                .converter(new StringConvert())//
                .adapt();
        Response<String> response = call.execute();

        final AtomicReference<Response<String>> responseRef1 = new AtomicReference<>();
        HttpUtils.runOnUiThread(() -> {
            OkLogger.e("同步请求响应:---" + response.body());
//                                textContent.setText(response.body());
//            handleResponse(response);
            responseRef1.set(response);
        });
        assertNotNull(responseRef1.get().body());

        assertNotNull("123456");

//        Assertions.assertThat("1234556").isEmpty();

    }


}